<%@ page language="java" import="java.util.*,com.hs.core.utils.*,com.hs.core.utils.*,com.hs.auth.model.*,com.hs.auth.*" pageEncoding="utf-8"%>
<%
   String pageStr = (String)request.getAttribute("pagestr");
   List datalist = (List)request.getAttribute("datalist");
   String pagenum = (String)request.getAttribute("pagenum");
   String pagecount = (String)request.getAttribute("pagecount");
   String allfullsql = (String)request.getAttribute("allfullsql");
   
	
   int pagenumInt = Integer.parseInt(pagenum==null?"0":pagenum);
   int pagecountInt = Integer.parseInt(pagecount==null?"0":pagecount);
   String orderName = (String)request.getAttribute("orderName");
   String orderNum = (String)request.getAttribute("orderNum");  
   String datatype = (String)request.getAttribute("datatype");  
   
   String onesql = (String)request.getAttribute("onesql");
   String searchtype = (String)request.getAttribute("searchtype");//基本检索、高级检索
   String issecond = (String)request.getAttribute("issecond"); 
   String tags = (String)request.getAttribute("tags"); 
   String searchstrinfo = (String)request.getAttribute("searchstrinfo"); 
   String keyword = (String)request.getAttribute("keyword"); 
  
   String beforesql = (String)request.getAttribute("beforesql"); 
   String paramstr = (String)request.getAttribute("paramstr"); 
   String onekeyword = (String)request.getAttribute("onekeyword"); 
   String onesearchinfo = (String)request.getAttribute("onesearchinfo"); 
   HsAccount accInfo = (HsAccount)session.getAttribute(AUTHConstant.USERINSESSION); 
    String accid = String.valueOf(accInfo==null?"":accInfo.getId());
   Map continfo = (Map)request.getAttribute("continfo");
   
   Map authMap = (Map)session.getAttribute("USERPOWER_"+accInfo.getId()); 
   if(authMap == null)
	authMap = new HashMap();
 
 boolean role4 = (authMap.get("SCHD_ROLE4")!=null); //题录检索人员
 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<%@ include file="../../include.jsp"%> 
 <script language=JavaScript>
var stype = <%=issecond%>;
if(stype !=null && stype !="" && stype!="0")
{
	var sbutton = window.parent.document.getElementById("secondsearch");
	sbutton.disabled=false;
}
 //题录信息
 function magaInfo(id)
{
	var pageURL = "<%=basePath %>data/magainfo.do?id=" + id;
	openwindow(pageURL,'800','600',''); 
}
//详细数据信息
 function auditInfo(id){
	var pageURL = "<%=basePath %>audit/auditlistFrame.do?id=" + id;
	openwindow(pageURL,'1000','800',''); 
    //window.location.href=pageURL;
 }
//排序
function orderPageLocal(cstr,orderNum){
 	  var conobj = window.parent.document.all.conditionurl;
	  if(conobj !=null && conobj !=undefined){
		  	var convalue = conobj.value;
		  	if(convalue.indexOf("?")!=-1 ){
		  		convalue +="&orderName="+cstr+"&orderNum="+orderNum;
		  	}else {
		  		convalue +="?orderName="+cstr+"&orderNum="+orderNum; 
		  	}
		  	window.parent.document.getElementById("bookframe").src = convalue;
	  } 
}
function exportResult(){
 	var checkObj =  document.all.checkmaga;
 	var magaid = "";
 	for(var i=0 ;i<checkObj.length; i++){
 		if(checkObj[i].checked){
 			magaid = magaid + checkObj[i].value + ",";
 		}
 	} 
 	if(magaid != ""){
 		var allsql = document.all.allsql.value;
 		document.exportform.action="<%=basePath%>search/exportMagaResult.do?magaid="+magaid+"&allsql="+ encodeURIComponent(allsql)+"&resulttype=1";	
  		document.exportform.submit();
 	}else{
 		alert("请选择要导出的数据!");
 	}
}
 
function exportAllResult(){
 	var allsql = document.all.allsql.value;
 	document.exportform.action="<%=basePath%>search/exportMagaResult.do?allsql="+ encodeURIComponent(allsql)+"&resulttype=2";	
  	document.exportform.submit();
 }
function viewresult(){


}
function changeDisplay(){
	var v = getRadioValue('displaytype');   
	window.parent.generalSearch(v,'');
}

function filterResultBasic(datatype){
   
    var paramstr = searchform.paramstr.value;  
    var onestr =  "?datatype="+datatype+paramstr; 
     //document.getElementById("resultlist").src="<%=basePath %>search/dosearch.do"+onestr;
    
    pageForm.action = "<%=basePath %>search/dosearch.do"+onestr;
 	pageForm.submit(); 
	//if(searchtype == 'basic_search'){
	    // alert(window.parent.searchinput.frameElement.src);
	    //parent.top.//.frames["searchinput"].generalSearch('',datatype);
	    
		//generalSearch('',datatype);
	//}else if(searchtype == 'advsearch'){
	  //  advSearch(datatype);
	//} 
}
function filterResult(datatype){
   
    /**var paramstr = searchform.paramstr.value;  
    var onestr =  "?datatype="+datatype;
    var strreplace = "datatype="+datatype;
    var sql = pageForm.searchSql.value;
    if("0" == datatype){
        
        var index = sql.indexOf("datatype=");
        if(-1 != index){
	        var sqlone = sql.substr(0,index);
	        var sqltwo = sql.substr(index+10,sql.length); 
	    	sql = sqlone + " 1=1" + sqltwo;
    	}
    } else{
       /** var index = sql.indexOf("1=");
        var count = 3;
        if(index == -1){
	        index = sql.indexOf("datatype=");
	        count = 10;
        }
        var sqlone = sql.substr(0,index);
        var sqltwo = sql.substr(index+count,sql.length); 
        //alert(sqlone);
        //alert(sqltwo);
	    sql = sqlone + " datatype=" + datatype + sqltwo;
	    
	    var index1 = sql.indexOf("where");
	    if(-1 != index1){
	        var sqlbefore  = sql.substr(0,index1);
	        alert(sqlbefore);
		    var sqlcontent = sql.substr(index1+5,sql.length);
		    alert(sqlcontent);
		    var index = sqlcontent.indexOf("order by");
		    var sqlone = sqlcontent.substr(0,index);
		    var sqltwo = sqlcontent.substr(index,sqlcontent.length);
		    alert(sqlone);
		    alert(sqltwo);
		    sql = sqlbefore + " where datatype="+datatype +" and ( "+sqlone+")"+sqltwo;
		    alert(sql);
	    }
	   
          	    
    }
    
    pageForm.searchSql.value = sql; 
    pageForm.action = "<%=basePath %>search/dosearch.do"+onestr;
    alert("<%=basePath %>search/dosearch.do"+onestr);
 	pageForm.submit(); 
 	*/
	//if(searchtype == 'basic_search'){
	    // alert(window.parent.searchinput.frameElement.src);
	  //  parent.top.//.frames["searchinput"].generalSearch('',datatype);
	    
		//generalSearch('',datatype);
	//}else if(searchtype == 'advsearch'){
	  //  advSearch(datatype);
	//} 
	  var stype = '<%=searchtype%>';
	  if("basic_search" == stype)   
	     window.parent.generalSearch('',datatype,'<%=basePath%>'); 
	  else
	     window.parent.advSearch(datatype,'<%=basePath%>');
}
function orderResult(colname,ordernum){
	var searchtype = document.getElementById('searchtype').value; 
	//var paramstr = searchform.paramstr.value; 
	pageForm.orderName.value = colname;
	pageForm.orderNum.value = ordernum;
	var sql = pageForm.searchSql.value;
	//a.title
	//a.bookname
	//a.bookcd
	//a.PERIODICALNAME
	//a.YEARSTR
	//alert(sql);
	var orderbystr = "";
	var index = sql.indexOf("order by");
	var index1 = sql.lastIndexOf("where");
	var sqlone = sql.substr(sql,index);
	var sqltwo = sql.substr(index1,sql.length); 
	if('1' == ordernum){
		orderbystr += ' order by ' + colname + " asc";
	}else{
		orderbystr += ' order by ' + colname + " desc";
	}
	sql = sqlone + orderbystr+') ' + sqltwo;
	//alert(sql);
	pageForm.searchSql.value = sql; 
    var onestr =  "?orderName="+colname+"&orderNum="+ordernum ;
    pageForm.action = "<%=basePath %>search/dosearch.do"+onestr;
 	pageForm.submit(); 
	/**
	if(searchtype == 'advmod'){ 
		advModSearch(colname,ordernum);
	}else if(searchtype == 'advbook'){
	    advBookSearch(colname,ordernum);
	}else if(searchtype == 'adveng'){
	    advEngSearch(colname,ordernum);
	}  
	*/
}
function exportData()
{
    var papers = getSelectPaper();
    if('' == papers){
    	alert('请选择要导出的文献!');
    	return;
    }
	document.dataform.action="<%=basePath%>search/exportAllData.do?ids="+papers;	
  	document.dataform.submit();
}
function getSelectPaper(){
	var ids = document.getElementsByName("paperid");    
    var idstr = "";          
    for (var i = 0; i < ids.length; i++)               
    {                     
           if(ids[i].checked){
           	 idstr += ids[i].value+",";
           }            
    }     
    return idstr;
}
$(document).ready(function(){
	$("#tipcontain").jTipsShow({
		delaytime:200,
		tipsTag: 'span',
		tipsTitle: 'title'
	}); 
});
function downloadpdf(pid,isimg){ 
	if('0' == isimg){
		alert("该文献尚未上传原文！");
		return;
	}else{
		openwindow('<%=basePath%>data/mod/downloadFile.do?pid='+pid,'0','0','');
	}
}
</script>
<style> 
 
.highlight { 
    background-color:#FF00FF; color:#FF0000;
} 

</style>
</head>
<body>
<div class="deta_sear_list">
    <div class="pageWrap">
    	<ul>
            <li><strong>中文文献</strong>(<font color=red><%=continfo.get("1")==null?"0":continfo.get("1") %></font>)</li>
            <li><strong>英文文献</strong>(<font color=red><%=continfo.get("2")==null?"0":continfo.get("2") %></font>)</li>
            <li><strong>古籍文献</strong>(<font color=red><%=continfo.get("3")==null?"0":continfo.get("3") %></font>)</li> 
        </ul>
         <div class="page">
         <%if("basic_search".equals(searchtype)){ %>
            <input type="radio" name="datatype" id="datatype" onclick="filterResult('0');" value="0" <%if("0".equals(datatype)){out.println(" checked");} %>/>全部文献
            <input type="radio" name="datatype" id="datatype" onclick="filterResult('1');" value="1" <%if("1".equals(datatype)){out.println(" checked");} %>/>中文期刊
            <input type="radio" name="datatype" id="datatype" onclick="filterResult('2');" value="2" <%if("2".equals(datatype)){out.println(" checked");} %>/>英文期刊
            <input type="radio" name="datatype" id="datatype" onclick="filterResult('3');" value="3" <%if("3".equals(datatype)){out.println(" checked");} %>/>古代文献
            <%} %>
         </div> 
    </div>
    <dl class="listWrap">
         <% if(null != datalist && datalist.size()>0){
                int counter = 0;
      		    for(int i =0;i<datalist.size();i++){
      			    Map dm = (Map)datalist.get(i);
      			    String type = dm.get("DATATYPE")+"";
      			    boolean oldOrMod = false;
      			    if("3".equals(type)){
      			    	oldOrMod = true;
      			    }
      			    counter++; 
      			    
          %> 
        <form name="dataform" action="<%=basePath %>search/exportAllData.do" method=post>
         <input type="hidden"  value="<%=onesql %>" name="onesql" id="onesql"/> 
           <input type="hidden"  value="<%=tags==null?"":tags %>" name="tags" id="tags"/> 
           <input type="hidden"  value="<%=searchtype %>" name="searchtype" id="searchtype"/> 
           <input type="hidden"  value="<%=paramstr==null?"":paramstr %>" name="paramstr" id="paramstr"/>  
           <input type="hidden"  value="<%=onekeyword==null?"":onekeyword %>" name="onekeyword" id="onekeyword"/>  
           <input type="hidden"  value="<%=allfullsql==null?"":allfullsql %>" name="allfullsql" id="allfullsql"/>  
           
           
        <dt><input name="paperid" type="checkbox" value="<%=dm.get("ID") %>" /> <%=(pagecountInt*(pagenumInt-1))+i+1 %> 
        <%if("1".equals(dm.get("ISIMG")+"")&&!role4){ %><a href="javaScript:downloadpdf('<%=dm.get("ID") %>');"><i class="mode_pdf"></i></a><%}else{%><i class="mode_pdf"></i> <%}%>
                      <%if(oldOrMod){
							out.print("<a href=javaScript:openwindow(\"");
							out.print(basePath);
							out.print("search/viewdetail.do?pid="+ dm.get("ID") );
							out.print("\",'800','600',''); style='text-decoration:none;' id=titleinfo title='"+dm.get("PERIODICALNAME")+"'>");
							out.print(SystemUtil.higiLight((String)dm.get("PERIODICALNAME"),null,keyword)); 
							out.print("</a>");
                         }else {
                            	  String title = (String)dm.get("TITLE");
                                  if(null == title)
                                     title = "";
                                  String temp = title.length()>80?title.substring(0,80)+"...":title;
                 				   out.print("<a  href=javaScript:openwindow(\"");
                 				   out.print(basePath);
                 				   out.print("search/viewdetail.do?pid="+ dm.get("ID") );
                 				   out.print("\",'800','600',''); style='text-decoration:none;' id=titleinfo title='"+title+"'>");
                                   out.print(SystemUtil.higiLight(temp,null,keyword)); 
                                 
                                   out.print("</a>"); 
                              		 
                              }%>  
        </dt>
        
        <dd>
            <a href="#">病名:</a><%=SystemUtil.higiLight(StringUtilTool.NULL2Blank((String)dm.get("DISNAME")),null,keyword)%><br /> 
            <a href="#"><%if(oldOrMod){ %>卷册章节:</a><%=StringUtilTool.NULL2Blank((String)dm.get("VOLUMESECTION"))%><%}else{ %>
                                    刊名:<%} %></a><%=SystemUtil.higiLight(StringUtilTool.NULL2Blank((String)dm.get("PERIODICALNAME")),null,keyword)%><br />
            <a href="#">作者：</a><%= SystemUtil.higiLight(StringUtilTool.NULL2Blank((String)dm.get("AUTHOR")),null,keyword)%><br />
            <a href="#"><%if(oldOrMod){ %>原文:<%}else{ %>摘要:<%} %></a>
            <%
	                String abstr = StringUtilTool.NULL2Blank((String)dm.get("ABSTRACT"));
	                if(abstr.length()>300){
	                	out.println(SystemUtil.higiLight(abstr.substring(0,300),null,keyword));
	                	out.println("...");
	                }else{
	                	out.println(SystemUtil.higiLight(abstr,null,keyword));
	                } 
	                %>
            <br />
            <%if(oldOrMod){%> <a href="#">中医病名:</a><%=SystemUtil.higiLight(StringUtilTool.NULL2Blank((String)dm.get("TCMNAME")),null,keyword)%><%}%>
            <%if(!oldOrMod){%> <a href="#">关键词:</a><%=SystemUtil.higiLight(StringUtilTool.NULL2Blank((String)dm.get("KEYWORD")),null,keyword)%><%}%><br/>
             
            <p><a href="javaScript:openwindow('<%=basePath %>search/viewdetail.do?pid=<%=dm.get("ID")%>','800','600','');">查看</a>
             <%if(!role4){ %><a href="javaScript:downloadpdf('<%=dm.get("ID") %>','<%=dm.get("ISIMG")%>');">下载</a><%} %></p>
        </dd>
        
        <%} %>
        
        <%}else{%>
        <dt>提示：</dt>
        <dd>
            <a href="#">没有符合查询条件的查询结果，请更换查询条件重试！</a>
        </dd>
         <%} %>
    </dl>
    
        </form>
    <div class="pageWrap">
        <div class="result">
          <input onclick="selectAll(true,'paperid');" type="button" value="全选" class="btn btn-primary"/>
            <input onclick="selectAll(false,'paperid');" type="button" value="清除" class="btn btn-primary"/>
            <input onclick="exportData();" type="button" value="导出" class="btn btn-primary"/>
        </div>
        <div class="page">
             <%=pageStr%>
        </div>
    </div>
</div><!--/检索结果-->
</body>
</html>

